<template>
	<view>
		<uni-section title="悬赏" type="line">
			<uni-card :title="list[inde].title" :sub-title="list[inde].money+'元'"
				:extra="'发起者'+list[inde].bountyGiverName" :thumbnail="avatar">
				<text class="uni-body">{{list[inde].requirementDescription}}</text>
			</uni-card>
		</uni-section>
		<uni-section title="接取悬赏？" type="line"></uni-section>
		<uni-easyinput class="uni-mt-5" trim="all" v-model="message" placeholder="自我推荐一下吧"></uni-easyinput>
		<uni-section title="确定接取悬赏？" type="line">
			<button type="primary" style="width: 500rpx;" @click="queding()">确定</button>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inde: '',
				token: '',
				list: [],
				message:'',
				searchUrl:'',
				searchUrl1:'',
				remessage:''
			}
		},
		components() {},
		methods: {
			queding(){
				if(this.message!=null){
					this.searchUrl='http://xg.kystu.cn:8085/system/bounty/receive'+"?id="+parseInt(this.list[this.inde].id)+"&message="+this.message;
					this.searchUrl1='http://xg.kystu.cn:8085/system/bounty/modifyMessage'+"?id="+parseInt(this.list[this.inde].id)+"&message="+this.message;
					this.Tosubmit();
				}else{
					uni.showToast({
						title: "自我介绍一下吧",
						icon: 'exception',
						duration: 850
					});
				}
			},
			Tosubmit(){
				var _this=this;
				uni.request({
					url: _this.searchUrl,
					method: "POST",
					header: {
						'Authorization': "Bearer " + _this.token
					},
					success: (res) => {
						if (res.data
							.code ==
							200) {
							uni.showToast({
								title: "提交成功",
								icon: 'exception',
								duration: 850
							});
							setTimeout(() => {
							uni.switchTab({
								url: '/pages/index'
							});
							}, 1000);
						}
						if(res.data.msg =="不能重复接取悬赏"){
							uni.request({
								url: _this.searchUrl1,
								method: "PUT",
								header: {
									'Authorization': "Bearer " + _this.token
								},
								success: (res) => {
									uni.showToast({
										title: "修改成功",
										icon: 'exception',
										duration: 850
									});
								}
							});
						}else{
							uni.showToast({
								title: res.data.msg,
								icon: 'exception',
								duration: 850
							});
						}
					}
				});
			},
			onLoad(option) {
				console.log('上一个页面传递过来的参数', option)
				console.log('id', option.index)
				this.inde = option.index
				// 接下来就是你需要该id做些什么，比如通过id查询到该详情等
			},
			onShow() {
				var _this = this;
				uni.getStorage({
					key: 'App-Token',
					success(res) {
						_this.token = res.data;
						uni.request({
							url: 'http://xg.kystu.cn:8085/system/reward/RewardList',
							method: "GET",
							header: {
								'Authorization': "Bearer " + _this.token
							},
							success: (res) => {
								if (res.data
									.code ==
									200) {
									uni.showToast({
										title: "查询成功",
										icon: 'exception',
										duration: 850
									});
									console.log(res.data.rows)
									_this.list = res.data.rows;
								}
							}
						});
					}
				})
			}
		}
	}
</script>

<style>

</style>
